package com.aegean.MonitorExamSYS.monitor.action;

import java.io.InputStream;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.monitor.business.MonitorBusiness;
import com.aegean.MonitorExamSYS.monitor.component.ExamineeState;
import com.aegean.MonitorExamSYS.monitor.component.MonitorValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("MonitorCheckPosition")
@Scope("prototype")
public class MonitorCheckPosition extends ActionSupport {
	@Resource
	MonitorBusiness business;
	private String exam_Name;
	private String start_Time;
	private String end_Time;
	private int position_Id;
	private String position_Name;
	private List<ExamineeState> examinees;
	private List<MonitorValue> monitors;

	public List<MonitorValue> getMonitors() {
		return monitors;
	}

	public void setMonitors(List<MonitorValue> monitors) {
		this.monitors = monitors;
	}

	private int totalCount;

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List<ExamineeState> getExaminees() {
		return examinees;
	}

	public void setExaminees(List<ExamineeState> examinees) {
		this.examinees = examinees;
	}

	public String getPosition_Name() {
		return position_Name;
	}

	public void setPosition_Name(String position_Name) {
		this.position_Name = position_Name;
	}

	public String getExam_Name() {
		return exam_Name;
	}

	public void setExam_Name(String exam_Name) {
		this.exam_Name = exam_Name;
	}

	public String getStart_Time() {
		return start_Time;
	}

	public void setStart_Time(String start_Time) {
		this.start_Time = start_Time;
	}

	public String getEnd_Time() {
		return end_Time;
	}

	public void setEnd_Time(String end_Time) {
		this.end_Time = end_Time;
	}

	public int getPosition_Id() {
		return position_Id;
	}

	public void setPosition_Id(int position_Id) {
		this.position_Id = position_Id;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		String root = ServletActionContext.getServletContext().getRealPath(
				"/temp");
		String position = ServletActionContext.getServletContext().getRealPath(
				"/temp/" + position_Id);
		examinees = business
				.showExamineeOnPosition(position_Id, root, position);
		monitors = business.showMonitorOnPosition(position_Id);
		totalCount = examinees.size();
		return SUCCESS;
	}

	public String downLoadExcel() throws Exception {
		return SUCCESS;
	}

	public InputStream getDownload() {
		try {
			String root = ServletActionContext.getServletContext().getRealPath(
					"/temp/" + position_Id);
			return business.downExcelPosition(position_Id, root,exam_Name,start_Time,end_Time,position_Name);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
}
